package com.vachel.editor.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.vachel.editor.R;
import com.vachel.editor.util.Utils;


public class NoticeDialog {


    public static final class Builder {

        private Context mContext;


        private ImageView mIvClose;

        private final Dialog dialog;

        public Builder(Context context) {
            this.mContext = context;
            View view = LayoutInflater.from(context).inflate(
                    R.layout.dialog_notice, null);

            mIvClose = view.findViewById(R.id.iv_close);


            // 定义Dialog布局和参数
            dialog = new Dialog(context, R.style.NoticeDialog);
            dialog.setContentView(view);
            Window dialogWindow = dialog.getWindow();
            dialogWindow.setGravity(Gravity.CENTER);
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.x = 0;
            lp.y = 0;
            lp.width = (int) (Utils.getScreenWidth(context));
            lp.height = (int) (Utils.getScreenHeight(context));
            lp.gravity = Gravity.CENTER;
            dialogWindow.setAttributes(lp);
        }

        public Builder build() {
            initData();
            return this;
        }

        private void initData() {
            mIvClose.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        }


        public Builder show() {
            dialog.show();
            return this;

        }

    }


}
